import { prisma } from '../../utils/prisma'

export default eventHandler(async (event) => {
  // @ts-expect-error context injected by middleware
  const auth = event.context.auth as { userId: number } | undefined
  if (!auth) throw createError({ statusCode: 401, statusMessage: 'UNAUTHORIZED' })
  const user = await prisma.user.findUnique({ where: { id: auth.userId }, select: { id: true, phone: true, createdAt: true } })
  return { user }
})


